package com.trt.beibei.api.v1;

import com.trt.beibei.exception.http.NotFoundException;
import com.trt.beibei.model.Category;
import com.trt.beibei.model.GridCategory;
import com.trt.beibei.service.CategoryService;
import com.trt.beibei.service.GridCategoryService;
import com.trt.beibei.vo.CategoryAllVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author tanrnetao
 * @date 2021-08-11
 * @desc 分类
 */
@RestController
@RequestMapping("category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @Autowired
    private GridCategoryService gridCategoryService;

    @GetMapping("/all")
    public CategoryAllVO getAll() {
        Map<Integer, List<Category>> categories = categoryService.getAll();
        return new CategoryAllVO(categories);
    }

    @GetMapping("/grid/all")
    public List<GridCategory> getGridCategoryList() {
        List<GridCategory> gridCategories = gridCategoryService.getGridCategoryList();
        if (gridCategories.isEmpty()) {
            throw new NotFoundException(30009);
        }
        return gridCategories;
    }

}
